package com.songdehuai.supermarket.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.songdehuai.supermarket.R;
import com.songdehuai.supermarket.supermarket.entity.SuperMarket;
import com.songdehuai.supermarket.utils.xUtilsImageUtils;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

public class ShopListAdapter extends RecyclerView.Adapter<ShopListAdapter.ViewHolder> {

    private Context context;
    private List<SuperMarket.ProductBean.ProductsBean> productsBeanList;

    public ShopListAdapter(Context context, List<SuperMarket.ProductBean.ProductsBean> productsBeanList) {
        this.context = context;
        this.productsBeanList = productsBeanList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_shop, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        SuperMarket.ProductBean.ProductsBean productsBean = productsBeanList.get(position);
        xUtilsImageUtils.display(holder.img, productsBean.getImage());
        holder.title.setText(productsBean.getProductname());
        holder.price.setText(productsBean.getPrice());
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return productsBeanList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        ImageView img;
        TextView title;
        TextView price;

        public ViewHolder(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.item_img);
            title = itemView.findViewById(R.id.item_title);
            price = itemView.findViewById(R.id.item_price_tv);
        }
    }
}
